package com.example.my.android;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.List;

public class ParkingActivity extends AppCompatActivity {

    private List<Parking> parkingList;
    private BaseAdapter parkingAdapter;
    private ListView parkingView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_parking);

        parkingView = findViewById(R.id.parking_view);
        ParkingUtil parkingUtil = new ParkingUtil(this);
        parkingList = parkingUtil.findList();
        parkingAdapter = new BaseAdapter() {
            @Override
            public int getCount() {
                return parkingList.size();
            }

            @Override
            public Object getItem(int position) {
                return parkingList.get(position);
            }

            @Override
            public long getItemId(int position) {
                Parking parking = (Parking) getItem(position);
                return parking.getId();
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                Parking parking = (Parking) getItem(position);

                if(convertView==null){
                    convertView = getLayoutInflater().inflate(android.R.layout.simple_list_item_2, parent, false);
                }

                TextView text1 = convertView.findViewById(android.R.id.text1);
                text1.setText(parking.getTitle());

                TextView text2 = convertView.findViewById(android.R.id.text2);
                text2.setText(parking.getLongitude() +" - " + parking.getLatitude());

                return convertView;
            }
        };
        parkingView.setAdapter(parkingAdapter);

    }
}